Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

This patch teaches DenseMap constructors to delegate to other DenseMap
constructors where we can.

The intent is for these constructors to build on top of a higher-level
concept like the default-constructed instance instead of calling init
on our own.

This is part of the effort outlined in #168255.

This patch teaches DenseMap constructors to delegate to other DenseMap
constructors where we can.

The intent is for these constructors to build on top of a higher-level
concept like the default-constructed instance instead of calling init
on our own.

This is part of the effort outlined in llvm#168255.
@llvmbot
Copy link
Member

llvmbot commented Nov 17, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

This patch teaches DenseMap constructors to delegate to other DenseMap
constructors where we can.

The intent is for these constructors to build on top of a higher-level
concept like the default-constructed instance instead of calling init
on our own.

This is part of the effort outlined in #168255.


Full diff: https://github.com/llvm/llvm-project/pull/168309.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMap.h (+8-18)
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 86592f12ce62c..fa87b812f9bf8 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -751,18 +751,12 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
     init(NumElementsToReserve);
   }
 
-  DenseMap(const DenseMap &other) : BaseT() {
-    init(0);
-    this->copyFrom(other);
-  }
+  DenseMap(const DenseMap &other) : DenseMap() { this->copyFrom(other); }
 
-  DenseMap(DenseMap &&other) : BaseT() {
-    init(0);
-    this->swap(other);
-  }
+  DenseMap(DenseMap &&other) : DenseMap() { this->swap(other); }
 
-  template <typename InputIt> DenseMap(const InputIt &I, const InputIt &E) {
-    init(std::distance(I, E));
+  template <typename InputIt>
+  DenseMap(const InputIt &I, const InputIt &E) : DenseMap(std::distance(I, E)) {
     this->insert(I, E);
   }
 
@@ -901,19 +895,15 @@ class SmallDenseMap
     init(NumElementsToReserve);
   }
 
-  SmallDenseMap(const SmallDenseMap &other) : BaseT() {
-    init(0);
+  SmallDenseMap(const SmallDenseMap &other) : SmallDenseMap() {
     this->copyFrom(other);
   }
 
-  SmallDenseMap(SmallDenseMap &&other) : BaseT() {
-    init(0);
-    this->swap(other);
-  }
+  SmallDenseMap(SmallDenseMap &&other) : SmallDenseMap() { this->swap(other); }
 
   template <typename InputIt>
-  SmallDenseMap(const InputIt &I, const InputIt &E) {
-    init(std::distance(I, E));
+  SmallDenseMap(const InputIt &I, const InputIt &E)
+      : SmallDenseMap(std::distance(I, E)) {
     this->insert(I, E);
   }
 

Copy link
Contributor

@s-barannikov s-barannikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kazutakahirata kazutakahirata merged commit b7a673c into llvm:main Nov 17, 2025
15 of 16 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20251116c_ADT_DenseMap_ctor branch November 17, 2025 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants